import time

import ImageProc
import ADBHelper
import RaphaelScriptHelper
from settings import *

REFRESH_TIME = 5  # s


class Img:
    screen = './cache/screenCap.png'
    fight = './img/Fight.jpg'

    class Fight:
        start_game = './img/Fight-startGame.jpg'
        back = './img/Fight-back.png'
        not_enough = ''

        class Skil:
            gun_子弹命中怪物后爆炸 = './img/Fight-skill-gun-baozha.png'
            gun_每次射击连发数加1 = './img/Fight-skill-gun-lianfashuliang.png'
            gun_子弹弹道数量加1 = './img/Fight-skill-gun-zidanshuliang.png'
            gun_将子弹变为火焰子弹 = './img/Fight_skill_gun_huoyanzidan.png'

            gun = './img/Fight-gun.png'
            fire_燃烧油桶 = './img/Fight-burnOil.png'
            car_车 = './img/Fight-car.png'
            boom = './img/Fight-boom.png'
            wind = './img/Fight-wind.png'
            air_boom = './img/Fight-airBoom.png'
            light = './img/Fight-light.png'
            guided_laser = './img/Fight-guidedLaser.png'
            air_knife = './img/Fight-airKnife.png'
            ice_bullet = './img/Fight-iceBullet.png'
            drop_down = './img/Fight-dropDown.png'
            diancicichuan = './img/Fight-diancicichuan.png'
            bingbaofashengqi = './img/Fight-bingbaofashengqi.png'
            yueqiandianzi = './img/Fight-yueqiandianzi.png'
            wurenjichongji = './img/Fight-wurenjichongji.png'
            dianjizhu = './img/Fight-dianjizhu.png'

            start_game = './img/Fight-startGame.jpg'
            back = './img/Fight-back.png'

            # blood = './img/Fight-blood.png'
            skill_first = [
                start_game, back,
                gun_子弹命中怪物后爆炸, gun_每次射击连发数加1, gun_子弹弹道数量加1, gun_将子弹变为火焰子弹,
                gun, fire_燃烧油桶, dianjizhu, wind, car_车, light, boom, wurenjichongji,
                air_boom, guided_laser, air_knife, ice_bullet, drop_down,
                diancicichuan, bingbaofashengqi, yueqiandianzi,
            ]


def is_game_over():
    return False


def have_play_advertisement():
    return False


def play_game(play_num=1):
    device = ADBHelper.getDevicesList()[0]
    print(f'当前连接的设备是: {device}')

    # 刷新屏幕
    ADBHelper.screenCapture(device, Img.screen)
    # return
    # point = ImageProc.locate(Img.screen, Img.Fight.start_game)
    # if point:
    #     ADBHelper.touch(device, point)

    while not ImageProc.locate(Img.screen, Img.Fight.back):

        point = ImageProc.locate(Img.screen, Img.Fight.start_game)
        if point:
            ADBHelper.touch(device, point)
            time.sleep(REFRESH_TIME * 5)
        ADBHelper.screenCapture(device, Img.screen)

        for skill in Img.Fight.Skil.skill_first:
            point = ImageProc.locate(Img.screen, skill)
            if point:
                print(point)
                ADBHelper.touch(device, point)
                break
        time.sleep(REFRESH_TIME)
    point = ImageProc.locate(Img.screen, Img.Fight.back)
    ADBHelper.touch(device, point)


if __name__ == '__main__':
    for _ in range(60):
        play_game()

    # print(f'{Img.Fight.startGame}')
